/**
 * Created by Admin on 2018/1/4.
 */
define(function (require, exports, module) {
    var template = require("template");
    var commonPaging=require("../common/commonPagingCq");
    var loadingTpl = require("../common/tpl/loading.html");
    var tpl = require("./tpl/dataManageTpl.html");
    require("../common/dialog");
    //require("../common/FileUpload/fileupload");


    var p=new commonPaging({
        htmlContainer: "#Js_page_content",
        pageContainer: "#Js_fs_paging",
        url: window.jkconfig.webapiurlv+"sys/datamanager/list",
        tpl:tpl,
        data:{pageSize:15,pageNumber:1}
    });
    p.init();

    var List = {
        bindEvent: function () {
            var self = this;
            $("body").on("click", ".btnDataDownLoad", function () {
                window.location.href = window.jkconfig.webapiurlv + "sys/datamanager/userfile?fileUrl=" + $(this).attr("data-fileUrl") + "&" + api_key + "=" + token;
            }).on("click", ".btnDataManageRemove", function () {
                var id = $(this).attr("data-id");
                $.ajax({
                    url: window.jkconfig.webapiurlv + "sys/datamanager/delete/" + id,
                    type: 'POST',
                    success: function (data) {
                        if (data.code == 0) {
                            alert("删除成功!");

                               window.location.reload();

                        } else {
                            alert(data.msg);
                        }
                    }
                })
            }).on("click", ".sy-dm-downname,.sy-dm-downbtn", function () {
                window.location.href = window.jkconfig.webapiurlv + "sys/datamanager/download?" + api_key + "=" + token;
            })
        }
    }


    List.bindEvent();
    $(function(){
        $(".Js_upload").change(function(){
            // var file = $(this).prop("files")[0];
            var fd = new FormData($('#uploadForm')[0]);
            $.ajax({
                url:window.jkconfig.webapiurlv+"sys/datamanager/import?"+api_key+"="+token,
                type:'POST',
                processData:false,
                contentType:false,
                data:fd,
                success:function(data){
                        if(data.code == 0){
                            alert("上传成功!");
                            setTimeout(function(){
                                window.location.reload();
                            },2000);
                        }else{
                            alert(data.msg);
                        }
                }
            })
        })
    })
})